package com.yyds.yygh.user.controller.api;

import com.yyds.yygh.common.result.Result;
import com.yyds.yygh.common.utils.AuthContextHolder;
import com.yyds.yygh.model.user.UserInfo;
import com.yyds.yygh.user.service.UserInfoService;
import com.yyds.yygh.vo.user.LoginVo;
import com.yyds.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户管理")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/login")
    @ApiOperation("登陆管理")
    public Result login(@RequestBody LoginVo loginVo){

        Map<String,Object> map = userInfoService.login(loginVo);
        return Result.success(map);
}
    @PostMapping("/auth/userAuth")
    @ApiOperation("实名认证")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo , HttpServletRequest request){
        //传递两个参数，第一个参数是用户id，第二个参数是认证数据vo对象
        Long userId = AuthContextHolder.getUserId(request);
        userInfoService.userAuth(userId,userAuthVo);
        return Result.success();
    }
    @GetMapping("/auth/getUserInfo")
    @ApiOperation("获取用户信息")
    public Result getUserInfo(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo users = userInfoService.getById(userId);
        return Result.success(users);
    }
}
